﻿Imports System.Data.OleDb

Public Class addhausaMathTerm
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click


        Dim newFileName As String

        newFileName = Guid.NewGuid().ToString() & getSuffix(thumbnailUpload.FileName)
        If thumbnailUpload.HasFile Then
            thumbnailUpload.SaveAs(Server.MapPath("Image") & "/" & newFileName)
        End If

        Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)
        Dim sql As String = "insert into Terms(Mathterm,Hausaterm,Definition,PictureSymbol,SiteAdd,Remark,DDate,Author,Category) values (@f1,@f2,@f3,@4,@f5,@f6,@f7,@f8,@f9)"

        Dim cmd As OleDbCommand = New OleDbCommand(sql, oleDbConn)
        cmd.CommandType = CommandType.Text
        cmd.Parameters.AddWithValue("@f1", txtEnglishTerm.Text.ToString())
        cmd.Parameters.AddWithValue("@f2", txtHausaTerm.Text.ToString())
        cmd.Parameters.AddWithValue("@f3", txtTermdefinition.Text.ToString())
        If thumbnailUpload.HasFile Then cmd.Parameters.AddWithValue("@f4", newFileName)
        cmd.Parameters.AddWithValue("@f5", txtSiteadress.Text.ToString())
        cmd.Parameters.AddWithValue("@f6", txtRemark.Text.ToString())
        cmd.Parameters.AddWithValue("@f7", Format(Date.Now(), "dd/MM/yyyy hh:mm:ss tt"))
        cmd.Parameters.AddWithValue("@f8", User.Identity.Name)
        cmd.Parameters.AddWithValue("@f9", ddlCategory.SelectedItem.ToString())
        oleDbConn.Open()
        cmd.ExecuteNonQuery()
        cmd.Dispose()
        oleDbConn.Close()
        oleDbConn.Dispose()
        Response.Redirect("Default.aspx")
    End Sub

    Function getSuffix(ByVal fn As String)
        Dim fileParts = fn.Split(".")
        Dim suffix = fileParts(fileParts.Length - 1)
        Return "." & suffix
    End Function

End Class